package com.logicbus.backend.bizlog;

import org.apache.commons.lang3.StringUtils;

import com.anysoft.util.Settings;
import com.logicbus.models.servant.ServiceDescription.LogType;

/**
 * BizLog输出的工具类
 * 
 * @author duanwaiwai
 * @since 1.6.12.36 [20190611 duanyy] <br>
 */
public class BizLog {
	protected static BizLogger bizLogger = null;
	public static void log(String sn,String service,String clientIp,String code,String reason,long time,long duration,String url){
		if (bizLogger == null){
			synchronized(BizLog.class){
				if (bizLogger == null){
					bizLogger = (BizLogger) Settings.get("bizLogger");
				}
			}
		}
		
		if (bizLogger != null){
			BizLogItem item = new BizLogItem();

			item.logType = LogType.brief;
			item.sn = sn;
			item.id = StringUtils.isEmpty(service)?"/core/Null":service;
			item.clientIP = clientIp;
			item.client = clientIp;
			item.result = code;
			item.reason = reason;
			item.startTime = time;
			item.duration = duration;
			item.url = url;
			item.content = null;
			item.contentLength = 0;
			
			bizLogger.handle(item, System.currentTimeMillis());
		}
	}
}
